function createNav() {
    const nav = document.createElement('nav');
    const token = localStorage.getItem('accessToken');

    nav.innerHTML = `
        <div class="navtitle"><strong>MJ</strong>|MY PROFILE</div>
        <a href="home.html">HOME</a>
        <a href="about.html">ABOUT</a>
        <a href="blog.html">BLOG</a>
        <a href="album.html">ALBUM</a>
        <a href="join.html">JOIN</a>
        ${token ?
            '<a href="javascript:void(0)" onclick="handleLogout()" class="login-link">退出</a>' :
            '<a href="login.html" class="login-link">登录</a>'
        }
    `;

    document.body.insertBefore(nav, document.body.firstChild);
}

// 当 DOM 加载完成后创建导航栏
document.addEventListener('DOMContentLoaded', createNav);

// 退出登录功能
window.handleLogout = () => {
    Swal.fire({
        title: '确认退出?',
        text: "您确定要退出登录吗？",
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#546d9e',
        cancelButtonColor: '#d33',
        confirmButtonText: '确定退出',
        cancelButtonText: '取消'
    }).then((result) => {
        if (result.isConfirmed) {
            localStorage.removeItem('accessToken');
            localStorage.removeItem('refreshToken');
            localStorage.removeItem('userInfo');
            window.location.href = 'login.html';
        }
    });
}; 